package com.tristia.entity.util;

import java.util.Comparator;

import com.tristia.entity.ItemInfo;

public class ItemInfoIdComparator implements Comparator<ItemInfo> {
	final static String ACS = "ACS";
	final static String DECS = "DECS";

	private String state;

	public ItemInfoIdComparator(String state) {
		this.state = state;
	}

	public ItemInfoIdComparator() {

	}

	public int compare(ItemInfo o1, ItemInfo o2) {
		if (state.equals(DECS)) {
//			System.out.println("DECS");
			return descendingSort(o1, o2);
		} else if (state.equals(ACS)) {
//			System.out.println("ACS");
			return ascendingSort(o1, o2);
		} else {
			System.out.println("Not a valid param.");
			return 0;
		}
	}

	// sort the object in descending way
	private int descendingSort(ItemInfo o1, ItemInfo o2) {
		if (o1.getId() < o2.getId()) {
			return 1;
		} else if (o1.getId() > o2.getId()) {
			return -1;
		} else
			return 0;
	}

	// sort the object in ascending way
	private int ascendingSort(ItemInfo o1, ItemInfo o2) {
		if (o1.getId() > o2.getId()) {
			return 1;
		} else if (o1.getId() < o2.getId()) {
			return -1;
		} else
			return 0;
	}
}
